/**
 * Created by QZP on 2020/5/24.
 */
// $.ajax({
//     url: "/fruit/fruitlist",
//     type: "post",
//     data: {},
//     dataType: "json",
//     success: function (jsonObj) {
//         console.log(jsonObj)
//
//         for (var i = 0; i < jsonObj.length; i++) {
//             console.log(jsonObj[i].fruitName)
//             var html = '';
//             html += '<div class="col-lg-6 box-style"><div class="pro-box" style="overflow: hidden"><div class="box-left"><div class="cen-button"><a href=""><img src="img/showfruit/收藏1.png" alt=""/></a></div><div class="cen-button"><a href=""><img src="img/showfruit/菜篮1.png" alt=""/></a></div>' +
//                 '<div class="cen-button" style="border-bottom: none"><a href=""><img src="img/showfruit/扩展1.png" alt=""/></a></div></div><div class="box-right"><div class="col-lg-7"><h3><a href=""><span>新鲜</span><strong>';
//             html += jsonObj[i].fruitName + '</strong></a></h3><p class="dec">' + jsonObj[i].fruitDescript + '</p><p class="price"><strong>￥' +
//                 jsonObj[i].fruitPrice + '</strong><del></del></p></div><div class="col-lg-5 box-img"><img src="';
//             html += jsonObj[i].other1 + '" alt=""/></div></div></div></div>';
//             $('div.shows').append(html);
//         }
//     }
// })


function requestData(pageNum) {
    $.ajax({
        // url: "/fruit/fruitlist",
        url: "/fruit/test",
        data:{
            pageSize:2,
            pageNum:pageNum,
        },
        dataType:"json",
        type:"post",
        success: function (data) {
            console.log(data)
            showData(data.fruitInfos)
            showPages(data.totalSize, data.pageSize, data.pageNum)
        }
    })
}






function search() {
    var fruitname = document.getElementById("sear").value;
    var lowprice = document.getElementById("lowprice").value;
    var upprice = document.getElementById("upprice").value;

}











function showData(jsonObj) {
    var html = '';
    for (var i = 0; i < jsonObj.length; i++) {
        console.log(jsonObj[i].fruitName)
        html += '<div class="col-lg-6 box-style"><div class="pro-box" style="overflow: hidden"><div class="box-left"><div class="cen-button"><a href=""><img src="img/showfruit/收藏1.png" alt=""/></a></div><div class="cen-button"><a href=""><img src="img/showfruit/菜篮1.png" alt=""/></a></div>' +
            '<div class="cen-button" style="border-bottom: none"><a href=""><img src="img/showfruit/扩展1.png" alt=""/></a></div></div><div class="box-right"><div class="col-lg-7"><h3><a href=""><span>新鲜</span><strong>';
        html += jsonObj[i].fruitName + '</strong></a></h3><p class="dec">' + jsonObj[i].fruitDescript + '</p><p class="price"><strong>￥' +
             jsonObj[i].fruitPrice + '</strong><del></del></p></div><div class="col-lg-5 box-img"><img src="';
         html += jsonObj[i].other1 + '" alt=""/></div></div></div></div>';
    }
    $('div.shows').html(html);
}

function showPages(totalSize,pageSize,pageNum){
    var totalPage
    if(totalSize%pageSize==0){
        totalPage = Math.floor(totalSize/pageSize)
    } else {
        totalPage = Math.floor(totalSize/pageSize + 1)
    }

    shtml =  "<li><span aria-hidden=\"true\">&laquo;</span></li>"
    for(var i = 1; i <= totalPage; i++){
        shtml = shtml + '<li '
        if(pageNum == i) {
            shtml = shtml + 'class="active"'
        }
        shtml = shtml + '> <span  onclick="requestData('
        shtml = shtml + i
        shtml = shtml + ')">'
        shtml = shtml + i
        shtml = shtml + "</span></li>"
    }
    shtml = shtml + '<li><span aria-hidden="true" onclick=requestData('
    if(pageNum == totalPage){
        shtml = shtml + pageNum
    } else {
        shtml= shtml + (pageNum + 1)
    }
    shtml = shtml + ')>&raquo;</span></li>'
    $(".pagination").html(shtml)
}

requestData(1);

























